package org.example;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class 第二十八章_ArrayList {
    public static void main(String[] args) {
        //创建ArrayList
        List<String> list = new ArrayList<>();
        //添加值
        list.add("1");
        list.add("2");
        list.add("7");
        list.add("4");
        list.add("5");
        list.add(1,"6");
        System.out.println(list);

        //访问元素
        System.out.println(list.get(2));

        //修改元素
        list.set(1,"10");
        System.out.println(list);

        //删除元素
        list.remove(1);
        System.out.println(list);

        //计算大小
        System.out.println(list.size());

        //迭代数组
        for (String string : list) {
            System.out.print(string);
        }
        System.out.println();

        //排序
        Collections.sort(list);
        System.out.println(list);
    }
}
